package com.kkb.cookie;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getCookie")
public class GetCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext = super.getServletContext();
        System.out.println(servletContext.getAttribute("contextServlet"));

        try {
            Cookie[] cookies = request.getCookies();
            for (Cookie cookie : cookies) {
                if ("cookieServlet".equals(cookie.getName())) {
                    String name = cookie.getName();
                    String value = cookie.getValue();

                    System.out.println(name + "--" + value);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
